package org.spring.boot.fusion.server.listening;

import com.netflix.appinfo.InstanceInfo;
import org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceCanceledEvent;
import org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceRegisteredEvent;
import org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceRenewedEvent;
import org.springframework.cloud.netflix.eureka.server.event.EurekaRegistryAvailableEvent;
import org.springframework.cloud.netflix.eureka.server.event.EurekaServerStartedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

@Component
public class EurekaStatusListener {

	@EventListener
	public void listen(EurekaInstanceCanceledEvent eurekaInstanceCanceledEvent) {
		String appName = eurekaInstanceCanceledEvent.getAppName();
		String serverId = eurekaInstanceCanceledEvent.getServerId();
		System.out.println("服务断线事件:" + appName + ":" + serverId);
	}

	@EventListener
	public void listen(EurekaInstanceRegisteredEvent event) {
		InstanceInfo instanceInfo = event.getInstanceInfo();
		System.out.println("服务注册事件:" + instanceInfo.getAppName());
	}

	@EventListener
	public void listen(EurekaInstanceRenewedEvent event) {
		String appName = event.getAppName();
		String serverId = event.getServerId();
		System.out.println("服务续约事件:" + appName + ":" + serverId);
	}

	@EventListener
	public void listen(EurekaRegistryAvailableEvent event) {
		System.out.println("注册中心启动事件:" + event);
	}

	@EventListener
	public void listen(EurekaServerStartedEvent event) {
		System.out.println("Server启动事件:" + event);
	}
}
